<script lang="ts" setup>
import { get, post, message, loadFile } from '@/utils'
import { FormInstance } from '@arco-design/web-vue'
import { Market } from '@/enum/market'
const props = defineProps<{
  show: boolean
  type: Market
  id: any //营销活动id
}>()
const emit = defineEmits(['update:show', 'reset', 'confirm'])
const formRef = ref() as Ref<FormInstance>
const detail = reactive({
  avatar: '',
  nickName: '',
  content: '',
  type: props.type,
  id: props.id,
  createTime: '',
})
const submit = done => {
  formRef.value.validate(err => {
    if (!err) {
      const query = Object.assign({}, detail)
      console.log('🚀 ~ file: index.vue:22 ~ formRef.value.validate ~ query:', query)

      post(
        { url: '/server-biz/sys-seller/dan/mu/publicity', data: query },
        ({ code, msg }) => {
          message({
            type: code == 200 ? 'success' : 'error',
            content: msg,
          })
          emit('update:show', false)
          emit('confirm')
          done(true)
        },
        () => done(false)
      )
    } else done(false)
  })
}
</script>
<template>
  <CModal v-model:visible="props.show" @before-ok="submit" :mask-closable="false" title="添加营销活动虚拟弹幕" @cancel="emit('update:show', false)">
    <div class="content">
      <a-form :model="detail" ref="formRef" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 16 }">
        <a-form-item label="用户头像">
          <Upload :list="detail.avatar" v-model:value="detail.avatar" :limit="1" />
        </a-form-item>
        <a-form-item label="用户昵称" field="nickName" :rules="[{ required: true, message: '请输入用户昵称' }]" :validate-trigger="['change', 'blur']">
          <a-input v-model="detail.nickName" placeholder="请输入用户昵称" />
        </a-form-item>
        <a-form-item label="显示时间" field="createTime" :rules="[{ required: true, message: '请选择显示时间' }]" :validate-trigger="['change', 'blur']">
          <a-date-picker style="width: 100%" show-time placeholder="请选择时间" format="YYYY-MM-DD HH:mm:ss" v-model="detail.createTime" />
        </a-form-item>
        <a-form-item label="显示内容" field="nickName" :rules="[{ required: true, message: '请输入显示内容' }]" :validate-trigger="['change', 'blur']">
          <a-textarea v-model="detail.content" placeholder="请输入显示内容" />
        </a-form-item>
      </a-form>
    </div>
  </CModal>
</template>
<style lang="less" scoped></style>
